package com.coolingme.springframework.aop;


import com.coolingme.springframework.aop.support.MeAdvisedSupport;

/**
 * AOP代理工厂，用于创建代理
 *
 * @author wangyue
 * @date 2024/9/9 22:22
 */
public class MeDefaultAopProxyFactory {
    public MeAopProxy createAopProxy(MeAdvisedSupport config) throws Exception {
        // 获取目标对象的Class
        Class targetClass = config.getTargetClass();
        // 如果实现接口，则使用JDK动态代理
        if (targetClass.getInterfaces().length > 0) {
            return new MeJdkDynamicAopProxy(config);
        }
        // 否则使用CGLIB动态代理
        return new MeCglibAopPorxy();
    }
}
